<?php
namespace app\activity\model;
use think\Model;
class User extends Model{
    protected $table = 'bk_user';
    protected $autoWriteTimestamp = 'datetime';
    public static function reg($data){
        $isReg = self::where('openid',$data['openid'])->find();
        if(!$isReg){
            $user = self::create($data);
            $data['user_id'] = $user->id;
        }else{
            $data['user_id'] = $isReg->id;
        }
        return $data;
    }

    public function hashHeadimgurl(){
        $list = self::all();
        $data=[];
        foreach($list as $k=>$v){
            $data[$v->id] = $v->headimgurl;
        }
        return $data;
    }

    public function getValue($where,$column='id'){
        return self::where($where)->value($column);
    }
}